/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.weed.sample.loggin;

import com.weed.core.CommonInput;
import com.weed.logging.Log;
import com.weed.logging.LogFactory;

import com.weed.net.*;
import com.weed.net.impl.HttpURLRequest;
import com.weed.net.listener.CallbackListener;
import java.net.CookieHandler;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Date;
import java.util.HashMap;

/**
 *
 * @author Jason zhuo
 */
public class Sample1 implements CallbackListener {
    static Log log = LogFactory.getLog(Sample1.class);
    
    public static void main(String[] args){
       try{
           HashMap config = new HashMap();
           config.put(SourceFactory.REQUEST_INTERFACE_IMPL, "com.weed.net.impl.HttpURLRequest");
           URL url = new URL("http://localhost:8080/test/Test2?id=111");
           config.put(HttpURLRequest.HTTP_URL,url);
           
           ISource source = SourceFactory.getInstance().buildSource(config);
           CommonInput input1 = new CommonInput();
/*         input1.set("001", "TEST");
           input1.set("002", 0.03f);
           input1.set("003", 43.00d);
           input1.set("004", new Date());
 */
           long time = System.currentTimeMillis();
           Object obj = source.submit(input1, new Sample1());
           config.put(HttpURLRequest.HTTP_URL,new URL("http://localhost:8080/test/Test2")); 
           source.submit(new CommonInput(), new Sample1());
           source.submit(new CommonInput(), new Sample1());
           source.submit(new CommonInput(), new Sample1());
           source.submit(new CommonInput(), new Sample1());
           source.submit(new CommonInput(), new Sample1());
           source.submit(new CommonInput(), new Sample1());
           source.submit(new CommonInput(), new Sample1());
           source.submit(new CommonInput(), new Sample1());
           source.submit(new CommonInput(), new Sample1());
           
           System.out.println(""+ (System.currentTimeMillis()-time) + "ms");
        }catch(Exception ex){
            log.error("print error!",ex);
       }
    }

    public void callback(IRequest request, Object data) {
         System.out.println("urlConnection:" + ((HttpURLRequest)request).getHttpURLConnection().getHeaderFields());
        // System.out.println(CookieHandler.getDefault());
    }
}
